/*
 * Copyright (C) 2023 HiHope Open Source Organization .
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 *
 * limitations under the License.
 */

#ifndef PZCAR_NET_CONFIG_H
#define PZCAR_NET_CONFIG_H

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>

#include "ohos_init.h"
#include "cmsis_os2.h"
#include "wifi_device.h"

#define AP_SSID         "HiCar001"
#define AP_PSWD         "12345678"
#define UDP_SERVERPORT  (3861)
#define TCP_SERVERPORT  (3862)

#define SERVER_UDP  (1)  // [1]-UDP Server
#define SERVER_TCP  (0)  // [1]-TCP Server
// 注意：当前项目中，任务数量已达到最大数量，当UDP Server和TCP Server同时运行的时候，
// UnisoundTask[云知声语音识别任务]就要关闭；
// 当退出 NetCtrl 模式的时候，如果需要在后台保持网络连接以及UDP Server在后台能工作，
// 就需要在UDP Server和TCP Server二选一

typedef enum {
    flag_0,  // 0-init
    flag_1,  // 1-bit0: UdpServer Recv SSID
    flag_2,  // 2-bit1: UdpServer Recv PSWD
    flag_3,  // 3-SSID+PSWD Ready
};

typedef enum {
    Net_ST_DisCon = 0,
    Net_ST_Conned = 1,
    Net_ST_Config = 2,
    Net_ST_MAX,
} NetState;

typedef enum {
    Net_MODE_NET_SERVER = 0,
    Net_MODE_NET_CONFIG,
    Net_MODE_NET_MAX,
} NetCtrlMode;

extern char ssid[64];
extern char pswd[64];
extern char flag;

WifiErrorCode RegisterWifiEventListener(void);
WifiErrorCode UnRegisterWifiEventListener(void);

void OnHotspotStateChanged(int state);
void OnHotspotStaJoin(StationInfo* info);
void OnHotspotStaLeave(StationInfo* info);
WifiErrorCode StartHotspot(void);
WifiErrorCode StopHotspot(void);

void OnWifiConnectionChanged(int state, WifiLinkedInfo* info);
void OnWifiScanStateChanged(int state, int size);
WifiErrorCode StartStation(void);
WifiErrorCode StopStation(void);

void ProcessRecvMsg(unsigned char *buff, int msgLen);
osThreadId_t UdpServRecvTaskEntry(void);
osThreadId_t UdpServSendTaskEntry(void);
osThreadId_t TcpServRecvTaskEntry(void);
osThreadId_t TcpServSendTaskEntry(void);
osThreadId_t NetCtrlTaskEntry(void);
#endif //PZCAR_NET_CONFIG_H